home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / profiles.pro < prev    next >
Text File  |  1997-07-08  |  5KB  |  173 lines

  1. ; $Id: profiles.pro,v 1.4 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. pro profiles, image, sx = sx, sy = sy, wsize = wsize, order = order
  7. ;+
  8. ; NAME:
  9. ;    PROFILES
  10. ;
  11. ; PURPOSE:
  12. ;    Interactively draw row or column profiles of an image in a separate
  13. ;    window.
  14. ;
  15. ; CATEGORY:
  16. ;    Image analysis.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    PROFILES, Image [, SX = sx, SY = sy]
  20. ;
  21. ; INPUTS:
  22. ;    Image:    The variable that represents the image displayed in current 
  23. ;        window.  This data need not be scaled into bytes.
  24. ;        The profile graphs are made from this array.
  25. ;
  26. ; KEYWORD PARAMETERS:
  27. ;    SX:    Starting X position of the image in the window.  If this 
  28. ;        keyword is omitted, 0 is assumed.
  29. ;
  30. ;    SY:    Starting Y position of the image in the window.  If this
  31. ;        keyword is omitted, 0 is assumed.
  32. ;
  33. ;    WSIZE:    The size of the PROFILES window as a fraction or multiple 
  34. ;        of 640 by 512.
  35. ;
  36. ;    ORDER:    Set this keyword param to 1 for images written top down or
  37. ;        0 for bottom up.  Default is the current value of !ORDER.
  38. ;
  39. ; OUTPUTS:
  40. ;    No explicit outputs.
  41. ;
  42. ; COMMON BLOCKS:
  43. ;    None.
  44. ;
  45. ; SIDE EFFECTS:
  46. ;    A new window is created and used for the profiles.  When done,
  47. ;    the new window is deleted.
  48. ;
  49. ; RESTRICTIONS:
  50. ;    None.
  51. ;
  52. ; PROCEDURE:
  53. ;    A new window is created and the mouse location in the original
  54. ;    window is used to plot profiles in the new window.  Pressing the
  55. ;    left mouse button toggles between row and column profiles.
  56. ;    The right mouse button exits.
  57. ;
  58. ; EXAMPLE:
  59. ;    Create and display an image and use the PROFILES routine on it.
  60. ;    Create and display the image by entering:
  61. ;
  62. ;        A = BYTSCL(DIST(256))
  63. ;        TV, A
  64. ;
  65. ;    Run the PROFILES routine by entering:
  66. ;
  67. ;        PROFILES, A
  68. ;
  69. ;    The PROFILES window should appear.  Move the cursor over the original
  70. ;    image to see the profile at the cursor position.  Press the left mouse
  71. ;    button to toggle between row and column profiles.  Press the right
  72. ;    mouse button (with the cursor over the original image) to exit the
  73. ;    routine.
  74. ;
  75. ; MODIFICATION HISTORY:
  76. ;    DMS, Nov, 1988.
  77. ;-
  78. on_error,2                              ;Return to caller if an error occurs
  79. if n_elements(sx) eq 0 then sx = 0    ;Default start of image
  80. if n_elements(sy) eq 0 then sy = 0
  81. if n_elements(wsize) eq 0 then wsize = .75
  82. s = size(image)
  83. maxv = max(image)             ;Get extrema
  84. minv = min(image)
  85. orig_w = !d.window
  86. nx = s[1]                ;Cols in image
  87. ny = s[2]                ;Rows in image
  88. IF (!Version.Os NE 'MacOS') THEN tvcrs,sx+nx/2,sy+ny/2,/dev ELSE tvcrs,1
  89. tickl = 0.1                ;Cross length
  90. print,'Left mouse button to toggle between rows and columns.'
  91. print,'Right mouse button to Exit.'
  92. window,/free ,xs=wsize*640, ys=wsize*512,title='Profiles' ;Make new window
  93. new_w = !d.window
  94. old_mode = -1                ;Mode = 0 for rows, 1 for cols
  95. old_font = !p.font            ;Use hdw font
  96. !p.font = 0
  97. mode = 0
  98. if n_elements(order) eq 0 then order = !order    ;Image order
  99.  
  100. while 1 do begin
  101.     wset,orig_w        ;Image window
  102.     cursor,x,y,2,/dev    ;Read position
  103.  
  104.     if !err eq 1 then begin
  105.         mode = 1-mode    ;Toggle mode
  106.         repeat cursor,x,y,0,/dev until !err eq 0
  107.         endif
  108.  
  109.     x = x - sx        ;Remove bias
  110.     y = y - sy
  111.     wset,new_w        ;Graph window
  112.  
  113.     if !err eq 4 then begin        ;Quit
  114.         wset,orig_w
  115.         IF (!Version.Os NE 'MacOS') THEN $
  116.             tvcrs,nx/2,ny/2,/dev    ;curs to old window
  117.         tvcrs,0                ;Invisible
  118.         wdelete, new_w
  119.         !p.font = old_font
  120.         return
  121.         endif
  122.     if mode ne old_mode then begin
  123.         old_mode = mode
  124.         first = 1
  125.         if mode then begin    ;Columns?
  126.             plot,[minv,maxv],[0,ny-1],/nodat,title='Column Profile'
  127.             vecy = findgen(ny)
  128.             crossx = [-tickl, tickl]*(maxv-minv)
  129.             crossy = [-tickl, tickl]*ny
  130.         end else begin
  131.             plot,[0,nx-1],[minv,maxv],/nodata,title='Row Profile'
  132.             vecx = findgen(nx)
  133.             crossx = [-tickl, tickl]*nx
  134.             crossy = [-tickl, tickl]*(maxv-minv)
  135.         endelse
  136.     endif
  137.  
  138.     if (x lt nx) and (y lt ny) and $
  139.         (x ge 0) and (y ge 0) then begin    ;Draw it
  140.         
  141.         if order then y = (ny-1)-y    ;Invert y?
  142.         if first eq 0 then begin    ;Erase?
  143.             plots, vecx, vecy, col=0    ;Erase graph
  144.             plots, old_x, old_y, col=0    ;Erase cross
  145.             plots, old_x1, old_y1, col=0
  146.             xyouts,.1,0,/norm,value,col=0    ;Erase text
  147.             empty
  148.           endif else first = 0
  149. ;;;;        value = string([x,y],format="('(',i4,',',i4,')')")
  150. ;;;;        value = strtrim(x,2) + string(y)
  151.         value = strmid(x,8,4)+strmid(y,8,4)
  152.         ixy = image[x,y]        ;Data value
  153.         if mode then begin        ;Columns?
  154.             vecx = image[x,*]    ;get column
  155.             old_x = crossx + ixy
  156.             old_y = [y,y]
  157.             old_x1 = [ixy, ixy]
  158.             old_y1 = crossy + y
  159.           endif else begin
  160.             vecy = image[*,y]    ;get row
  161.             old_x = [ x,x]
  162.             old_y = crossy + ixy
  163.             old_x1 = crossx + x
  164.             old_y1 = [ixy,ixy]
  165.           endelse
  166.         xyouts,.1,0,/norm,value    ;Text of locn
  167.         plots,vecx,vecy        ;Graph
  168.         plots,old_x, old_y    ;Cross
  169.         plots,old_x1, old_y1
  170.         endif
  171. endwhile
  172. end
  173.